import {
    fetchBy,
} from '../services/service.js'
export default {
    namespace: 'channel',
    state: {
        dataSource: [],
    },

    subscriptions: {
        setup({ dispatch, history }) {  // eslint-disable-line
        },
    },

    effects: {
        * fetchChannel({ payload }, { call, put }) {
            const response = yield call(fetchBy, payload);
            console.log("response:" + response);
            if (!response || response.code != '0') {
                return false;
            }
            //存储数据源,发送事件至reducers中
            yield put({
                type: 'saveFetchChannelData',
                payload: response.data,
            });
            return true;
        }
    },

    reducers: {
        save(state, action) {
            return { ...state, ...action.payload };
        },
        saveFetchChannelData(state, action) {
            return {
                ...state,
                list: action.payload.response,
            }
        }
    },

};
